
#### 01/24/2013, Navid Hassapour, navid.hassanpour@yale.edu #####

########## REGRESSIONS ##########

setwd("/Your Folder/Cairo-Survey/")
library(MASS)
library(aod)

CairoMM <- read.csv(file="Cairo-Survey-Data.csv",head=TRUE,sep=",")

##############table 1 ##################

tab1c1<-glm(CairoMM$Part28 ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E+ CairoMM$Media1F  ,family="binomial")

summary(tab1c1)

tab1c2<-glm(CairoMM$Part28 ~ CairoMM$Media28A + CairoMM$Media28B + CairoMM$Media28C + CairoMM$Media28E+ CairoMM$Media28F ,family="binomial")

summary(tab1c2)

tab1c3<-glm(CairoMM$Part28 ~ CairoMM$Media28A + CairoMM$Media28B + CairoMM$Media28C + CairoMM$Media28E+ CairoMM$Media28F + CairoMM$Part25 ,family="binomial")

summary(tab1c3)

tab1c4<-glm(CairoMM$Part28 ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E+ CairoMM$Media1F + CairoMM$Part25 ,family="binomial")

summary(tab1c4)

tab1c5<-glm(CairoMM$Part28 ~ CairoMM$Media28A + CairoMM$Media28B + CairoMM$Media28C + CairoMM$Media28E+ CairoMM$Media28F + CairoMM$Part25 + CairoMM$online ,family="binomial")

summary(tab1c5)

tab1c6<-glm(CairoMM$Part28 ~ CairoMM$Part25 + CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E+ CairoMM$Media1F + CairoMM$Media28A + CairoMM$Media28B + CairoMM$Media28C + CairoMM$Media28E+ CairoMM$Media28F + CairoMM$Part25 + CairoMM$online ,family="binomial")

summary(tab1c6)
#########################################

##############table 2 ##################

tab2c1<-glm(CairoMM$Part25 ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E+ CairoMM$Media1F ,family="binomial")

summary(tab2c1)

tab2c2<-glm(CairoMM$Part25 ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E+ CairoMM$Media1D*CairoMM$Media1E + CairoMM$Media1F ,family="binomial")

summary(tab2c2)

tab2c3<-glm(CairoMM$Part28 ~ CairoMM$Media28A + CairoMM$Media28B + CairoMM$Media28C + CairoMM$Media28E+ CairoMM$Media28F ,family="binomial")

summary(tab2c3)

tab2c4<-glm(CairoMM$Part29 ~ CairoMM$Media29A + CairoMM$Media29B + CairoMM$Media29C + CairoMM$Media29E+ CairoMM$Media29F ,family="binomial")

summary(tab2c4)

tab2c5<-glm(CairoMM$Part3 ~ CairoMM$Media29A + CairoMM$Media29B + CairoMM$Media29C + CairoMM$Media29E+ CairoMM$Media29F ,family="binomial")

summary(tab2c5)


#########################################

##############table 3 ##################

tab3c1<-glm(CairoMM$Shut ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E+ CairoMM$Media1F + CairoMM$Media28A + CairoMM$Media28B + CairoMM$Media28C + CairoMM$Media28E+ CairoMM$Media28F+ CairoMM$Part25 ,family="binomial")

summary(tab3c1)

tab3c2<-glm(CairoMM$Shut ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E+ CairoMM$Media1F,family="binomial")

summary(tab3c2)

tab3c3<-glm(CairoMM$Shut ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E+ CairoMM$Media1F + CairoMM$Part25 + CairoMM$online ,family="binomial")

summary(tab3c3)

tab3c4<-glm(CairoMM$Shut ~ CairoMM$Media28A + CairoMM$Media28B + CairoMM$Media28C + CairoMM$Media28E+ CairoMM$Media28F + CairoMM$Part25 + CairoMM$online ,family="binomial")

summary(tab3c4)

tab3c5<-glm(CairoMM$Shut ~ CairoMM$Media28A + CairoMM$Media28B + CairoMM$Media28C + CairoMM$Media28E+ CairoMM$Media28F + CairoMM$online ,family="binomial")

summary(tab3c5)

#########################################

##############table 4 ##################

tab4c1<-glm(CairoMM$Media28E ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E + CairoMM$Media1F + CairoMM$Part25 +CairoMM$online,family="binomial")

summary(tab4c1)

tab4c2<-glm(CairoMM$Media28F ~ CairoMM$Media1A + CairoMM$Media1B + CairoMM$Media1C + CairoMM$Media1D + CairoMM$Media1E + CairoMM$Media1F + CairoMM$Part25 +CairoMM$online,family="binomial")

summary(tab4c2)

#########################################
#########################################
#########################################



######## FIGURES ##############

##########The vanguard among the online people ####### 

NumspOR <-c(84,84,84,84)
NumstOR <-c(60,84,60,84)

TotalpOR <-c(98.8)
TotaltOR <-c(92.9)

# 53 are missing from Tahrir 25 and Tahrir 29 240-53=187

particOR<-  c(100 ,84.5,79.8,94.0)
tahrirpOR<- c(80  ,50.0,65.0,86.9)

CIpOR <- sqrt(.01*particOR*(1-.01*particOR)/NumspOR)
CItOR <- sqrt(.01*tahrirpOR*(1-.01*tahrirpOR)/NumstOR)

percentsOR<- tahrirpOR/particOR


################# ONLINE PARTICIPANTS
TotalpO <-c(68.3)
TotaltO <-c(67.1)

NumspO <-c(240,240,240,240)
NumstO <-c(187,240,187,240)

# 53 are missing from Tahrir 25 and Tahrir 29 240-53=187

particO<-  c(35  ,50.4,51.7,66.3)
tahrirpO<- c(29.4,26.7,42.8,64.6)

CIpO <- sqrt(.01*particO*(1-.01*particO)/NumspO)
CItO <- sqrt(.01*tahrirpO*(1-.01*tahrirpO)/NumstO)

#############################
TotalpP <-c(54.6)
TotaltP <-c(53.0)

NumspP <-c(500,500,500,500)
NumstP <-c(500,500,500,500)

particP<-  c(26.8,35.8,33.4,45.2)
tahrirpP<- c(25.2,28.0,31.8,44.6)

CIpP <- sqrt(.01*particP*(1-.01*particP)/NumspP)
CItP <- sqrt(.01*tahrirpP*(1-.01*tahrirpP)/NumstP)

###############################
TotalpM <-c(59.1)
TotaltM <-c(57.6)

NumspM <-c(740,740,740,740)
NumstM <-c(687,740,687,740)

particM<-  c(29.5,40.5,39.3,52.0)
tahrirpM<- c(26.3,27.6,34.8,51.1)

CIpM <- sqrt(.01*particM*(1-.01*particM)/NumspM)
CItM <- sqrt(.01*tahrirpM*(1-.01*tahrirpM)/NumstM)


############################
percentsO<- tahrirpO/particO
percentsP<- tahrirpP/particP
percentsM<- tahrirpM/particM
#####################


########### Figure(5) -- All #######

grange<- range(0,100)
 plot(particM, type="o", col="blue", ylim=grange, 
   axes=FALSE, ann=FALSE)
barx2<- axis(1, at=1:4, lab=c("25-27","28","29-1","3-11"))
axis(2, las=1, at=10*0:grange[2])
box()
lines(tahrirpM, type="o", pch=22, lty=2, col="red")
legend(1, grange[2], c("in protests","in Tahrir"), cex=1.2, 
   col=c("blue","red"), pch=21:22, lty=1:2);
title(xlab="Date")
title(ylab="Percentage of Participation")
title(main="Participation Levels among All Respondents", font.main=2)
arrows(barx2,particM+100*CIpM, barx2, particM-100*CIpM, angle=90, code=3, length=.1)
arrows(barx2,tahrirpM+100*CItM, barx2, tahrirpM-100*CItM, angle=90, code=3, length=.1)

grid( col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)


###### Figure(6) -- Online #######

grange<- range(0,100)
 plot(particO, type="o", col="blue", ylim=grange, 
   axes=FALSE, ann=FALSE)
barx2<- axis(1, at=1:4, lab=c("25-27","28","29-1","3-11"))
axis(2, las=1, at=10*0:grange[2])
box()
lines(tahrirpO, type="o", pch=22, lty=2, col="red")
legend(1, grange[2], c("in protests","in Tahrir"), cex=1.2, 
   col=c("blue","red"), pch=21:22, lty=1:2);
title(xlab="Date")
title(ylab="Percentage of Participation")
title(main="Participation Levels among Online Respondents", font.main=2)
arrows(barx2,particO+100*CIpO, barx2, particO-100*CIpO, angle=90, code=3, length=.1)
arrows(barx2,tahrirpO+100*CItO, barx2, tahrirpO-100*CItO, angle=90, code=3, length=.1)

grid( col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)



############### Figure(7) -- Face to Face ##########

grange<- range(0,100)
 plot(particP, type="o", col="blue", ylim=grange, 
   axes=FALSE, ann=FALSE)
barx2<- axis(1, at=1:4, lab=c("25-27","28","29-1","3-11"))
axis(2, las=1, at=10*0:grange[2])
box()
lines(tahrirpP, type="o", pch=22, lty=2, col="red")
legend(1, grange[2], c("in protests","in Tahrir"), cex=1.2, 
   col=c("blue","red"), pch=21:22, lty=1:2);
title(xlab="Date")
title(ylab="Percentage of Participation")
title(main="Participation Levels among Face-to-Face Respondents", font.main=2)
arrows(barx2,particP+100*CIpP, barx2, particP-100*CIpP, angle=90, code=3, length=.1)
arrows(barx2,tahrirpP+100*CItP, barx2, tahrirpP-100*CItP, angle=90, code=3, length=.1)

grid( col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)



########### Media Usage ######################
###############################



########################### Figure(2) All ########

NumsMed <-c(740,740,740)
#NumstM <-c(740,740,740)

StateTV <-  c(12.0,14.2,14.3)
SatTV   <-  c(40.4,73.5,83.0)
NewsP   <-  c( 9.1,11.8,15.8)
Inter   <-  c(71.5,0   ,0   )
Frien   <-  c(43.9,52.6,55.8)
Other   <-  c( 4.2,12.4, 8.0)

MatrixMed2 <-rbind(StateTV,SatTV,NewsP,Inter,Frien,Other)

CIS1 <- sqrt(.01*StateTV*(1-.01*StateTV)/NumsMed)
CIS2 <- sqrt(.01*SatTV*(1-.01*SatTV)/NumsMed)
CIN1 <- sqrt(.01*NewsP*(1-.01*NewsP)/NumsMed)
CII1 <- sqrt(.01*Inter*(1-.01*Inter)/NumsMed)
CIF1 <- sqrt(.01*Frien*(1-.01*Frien)/NumsMed)
CIO1 <- sqrt(.01*Other*(1-.01*Other)/NumsMed)


barplot(MatrixMed2, main="Media Usage", names.arg=c("1st Time","28th","29th-1st"), ylab= "Percentage",xlab="Date", beside=TRUE, col=rainbow(6))

legend("topleft", c("State TV/Radio","Satellite TV","Newspaper","Internet","Friends & Acquaintances","Other"), cex=1, bty="n", fill=rainbow(6));

grid( col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)

#Percentage of the respondents who reported using these sources on these dates - Include confidence intervals .


######################## Figure(3) The vanguard ################# 

NumsMedR <-c(218,218,218)

StateTVR <-  c(2.3 ,9.6 ,6.9)
SatTVR   <-  c(26.6,57.8,75.7)
NewsPR   <-  c(7.8 ,11.9,13.3)
InterR   <-  c(85.8,0   ,0 )
FrienR   <-  c(48.2,59.2,61.5)
OtherR   <-  c( 5.0,22.9 ,14.2)

MatrixMedR <-rbind(StateTVR,SatTVR,NewsPR,InterR,FrienR,OtherR)

CIS1R <- sqrt(.01*StateTVR*(1-.01*StateTVR)/NumsMedR)
CIS2R <- sqrt(.01*SatTVR*(1-.01*SatTVR)/NumsMedR)
CIN1R <- sqrt(.01*NewsPR*(1-.01*NewsPR)/NumsMedR)
CII1R <- sqrt(.01*InterR*(1-.01*InterR)/NumsMedR)
CIF1R <- sqrt(.01*FrienR*(1-.01*FrienR)/NumsMedR)
CIO1R <- sqrt(.01*OtherR*(1-.01*OtherR)/NumsMedR)

barplot(MatrixMedR, main="Media Usage Among The Vanguard", names.arg=c("1st Time","28th","29th-1st"), ylab= "Percentage",xlab="Date", beside=TRUE, col=rainbow(6))

legend("topleft", c("State TV/Radio","Satellite TV","Newspaper","Internet","Friends & Acquaintances","Other"), cex=1, bty="n", fill=rainbow(6));

grid( col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)

#Percentage of the respondents who reported using these sources on these dates - Include confidence intervals .

#################### Figure(4) Nonparticipants #############

NumsMedC <-c(303,303,303)

StateTVC <-  c(22.1 ,21.5 ,21.8)
SatTVC   <-  c(49.5,82.5,86.8)
NewsPC   <-  c(12.2 ,15.5,19.8)
InterC   <-  c(56.1,0   ,0 )
FrienC   <-  c(36.0,43.9,46.9)
OtherC   <-  c( 3.6,4.3 ,3.6)

MatrixMedC <-rbind(StateTVC,SatTVC,NewsPC,InterC,FrienC,OtherC)

CIS1C <- sqrt(.01*StateTVC*(1-.01*StateTVC)/NumsMedC)
CIS2C <- sqrt(.01*SatTVC*(1-.01*SatTVC)/NumsMedC)
CIN1C <- sqrt(.01*NewsPC*(1-.01*NewsPC)/NumsMedC)
CII1C <- sqrt(.01*InterC*(1-.01*InterC)/NumsMedC)
CIF1C <- sqrt(.01*FrienC*(1-.01*FrienC)/NumsMedC)
CIO1C <- sqrt(.01*OtherC*(1-.01*OtherC)/NumsMedC)

barplot(MatrixMedC, main="Media Usage Among Nonparticipants", names.arg=c("1st Time","28th","29th-1st"), ylab= "Percentage",xlab="Date", beside=TRUE, col=rainbow(6))

legend("topleft", c("State TV/Radio","Satellite TV","Newspaper","Internet","Friends & Acquaintances","Other"), cex=1, bty="n", fill=rainbow(6));

grid( col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)

#Percentage of the respondents who reported using these sources on these dates - Include confidence intervals .

############################################
